// pages/thing/thingdetail.js


Page({
  mixins: [require('../mixin/themeChanged')],

  /**
   * 页面的初始数据
   */
  data: {
    sn: "",
    thingorder: [],
    currentid: "",
    thinginput:[],
    city:"",

  },
  scanqrCode:function(e){
    var that = this
    var url = wx.getStorageSync("config")
    wx.scanCode({
      onlyFromCamera: false,
      scanType: ['qrCode'],
      success: (res) => {
        console.log(res.result)
        that.setData({
          sn:res.result
        })
        console.log(that.data.sn.slice(0,1))

        if(that.data.sn.slice(0,2)=="LY"){
          wx.request({
            url: url.service.homeUrl + '/thing/getthingorderdetail',
            data: {
              sn: that.data.sn
            },
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {
      
              that.setData({
                thingorder: res.data,
              })
      
      
            },
            fail: function (res) {},
            complete: function (res) {},
          })
        }

        else{
          wx.request({
            url: url.service.homeUrl + '/thing/getthingorderdetail',
            data: {
              sn: that.data.sn
            },
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {
      
              that.setData({
                thinginput: res.data,
              })
      
      
            },
            fail: function (res) {},
            complete: function (res) {},
          })
        }

      },
      fail: (res) => {},
      complete: (res) => {},
    })

  },
  

  changeMark: function (e) {
    var that = this
    var url = wx.getStorageSync("config")
    //得到当前点击数据的id号
    this.setData({
      currentid: e.currentTarget.dataset.id
    })
    console.log(e.currentTarget.dataset.id)


    wx.showModal({
      title: '删除确认',
      content: '请核对删除内容是否正确',
      success: function (res) {
        if (res.confirm) {


          //请求体
          wx.request({
            url: url.service.homeUrl + '/thing/changethingmark',
            data: {
              id: that.data.currentid,
              mark: 0
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {

              wx.showToast({
                title: res.data.msg,
              });

              that.load()

            },
            fail: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
            complete: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
          })




        }
      }
    })
  },


  changeAllMark: function () {
    var that = this
    var url = wx.getStorageSync("config")

    wx.showModal({
      title: '删除确认',
      content: '请核对删除内容是否正确',
      success: function (res) {
        if (res.confirm) {


          wx.request({
            url: url.service.homeUrl + '/thing/changethingallmark',
            data: {
              sn: that.data.sn,
              mark: 0
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {

              wx.showToast({
                title: res.data.msg,
              })
              wx.navigateTo({
                url: '../thing/thingadmin',
              })

            },
            fail: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
            complete: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
          })

        }
      }
    })


  },


  bindPost: function () {
    var that = this
    var url = wx.getStorageSync("config")

    wx.showModal({
      title: '出库确认',
      content: '请核对出库内容是否正确',
      success: function (res) {
        if (res.confirm) {


          wx.request({
            url: url.service.homeUrl + '/thing/adminchange',
            data: {
              sn: that.data.sn,
              mark: 2,
              city:that.data.city,
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {

              wx.showToast({
                title: res.data.msg,
              })
              wx.navigateTo({
                url: '../thing/thingadmin',
              })

            },
            fail: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
            complete: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
          })

        }
      }
    })




  },

  
  bindPostRk:function(e){

    var that = this
    var url = wx.getStorageSync("config")

    wx.showModal({
      title: '出库确认',
      content: '请核对出库内容是否正确',
      success: function (res) {
        if (res.confirm) {


          wx.request({
            url: url.service.homeUrl + '/thing/adminrkchange',
            data: {
              sn: that.data.sn,
              mark: 2,
              city:that.data.city,
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {

              wx.showToast({
                title: res.data.msg,
              })
              wx.navigateTo({
                url: '../thing/thingadmin',
              })

            },
            fail: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
            complete: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
          })

        }
      }
    })

  },



  
  changeTheme: function() {
    console.log(this.data);
    getApp().themeChanged(this.data.theme === 'light' ? 'dark' : 'light');
},



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      city: wx.getStorageSync('city')
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})